using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;

namespace ObjectThinking.Diagnostics
{
    public static class DebugViolations
    {
        public static void Write(ISelf obj)
        {
            if ((obj != null) && (obj.Rules != null) && (obj.Rules.Count != 0))
            {
                foreach (IRule rule in obj.Rules)
                {
                    foreach (KeyValuePair<Uri, Object> pair in rule)
                    {
                        IViolation violation = (pair.Value as IViolation);

                        if (violation != null)
                        {
                            Debug.WriteLine(
                                String.Format(CultureInfo.InvariantCulture, "{0}[{1}]: {2}[{3}]: \"{4}\"", obj, pair.Key, rule, violation, violation.Description)
                                );
                        }
                    }
                }

                foreach (KeyValuePair<Uri, Object> pair in obj)
                {
                    Write(pair.Value as ISelf);
                }
            }
        }
    }
}